{% extends "kbforums/base.html" %}
{% from "layout/errorlist.html" import errorlist %}
{% from "includes/common_macros.html" import content_editor with context %}
{% from "kbforums/includes/macros.html" import kbforums_warning with context %}
{# L10n: {t} is the title of the thread. {d} is the name of the document. #}
{% set title = _('Edit a post | {t} | {d} Discussion | Knowledge Base')|f(t=thread.title, d=document.title) %}
{% set crumbs = [(document.get_absolute_url(), document.title),
                 (url('wiki.discuss.threads', document.slug), _('Discuss')),
                 (url('wiki.discuss.posts', document.slug, thread.id), thread.title),
                 (None, _('Edit a post'))] %}
{% set styles = ('forums', 'jqueryui') %}
{% set scripts = ('forums', 'jqueryui') %}

{% block content %}
  <article id="edit-post" class="grid_9">
    {{ kbforums_warning(document, user) }}
    <h1>{{ _('Edit a post') }}</h1>

    <form action="{{ url('wiki.discuss.edit_post', document.slug, thread.id, post.id) }}" method="post" class="edit-post">
      {% csrf_token %}
      {{ errorlist(form) }}

      <div class="form-widget{% if form.content.errors %} invalid{% endif %}">
        {{ form.content.label_tag()|safe }}
        <div class="content-box">
          {{ content_editor(form.content) }}
        </div>
      </div>

      <div class="form-widget submit">
        <button type="submit" class="btn btn-submit big">{{ _('Update post') }}</button>
        <button type="submit" id="preview" name="preview" class="btn"
            data-preview-url="{{ url('wiki.discuss.post_preview_async', document.slug) }}"
            data-preview-container-id="post-preview"
            data-preview-content-id="id_content">{{ _('Preview') }}
        </button>
        <a class="btn" href="{{ url('wiki.discuss.posts', document.slug, thread.id) }}">{{ _('Cancel') }}</a>
      </div>
    </form>

    <div id="post-preview">
      {% if post_preview %}
        {% include "kbforums/includes/post_preview.html" %}
      {% endif %}
    </div>
  </article>
{% endblock %}
